package com.library.utils.Tick
{
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	

    public class Tick extends EventDispatcher {

        private const _delay:int = 500;

        private var _timer:Timer;

        public function Tick(){
            _timer = new Timer(_delay, 0);
            _timer.addEventListener(TimerEvent.TIMER, onTimer);
            _timer.start();
        }
        private function onTimer(evt:TimerEvent):void{
            if (_instance.hasEventListener(TickEvent.TICK) == false){
                _timer.removeEventListener(TimerEvent.TIMER, onTimer);
                _instance._timer.stop();
                _instance = null;
            };
            dispatchEvent(new TickEvent(TickEvent.TICK, false, false));
        }
        
        // Singleton
        private static var _instance:Tick;
        public static function getInstance() : Tick {
            if ( _instance == null ) _instance = new Tick( );
            return _instance as Tick;
        }

    }
}
